const connection = require("../app/database");
class UserService {
  async create(user) {
    const { name, password, cellphone, email, avatar, pad, ps_id } = user;
    const statement = `INSERT INTO user (name, password, cellphone, email, avatar, pad,ps_id) VALUES (?,?,?,?,?,?,?);`;
    const result = await connection.execute(statement, [
      name,
      password,
      cellphone,
      email,
      avatar,
      pad,
      ps_id
    ]);
    console.log("service", user);
    return result;
  }
  async getUserByName(name) {
    try {
      const statement = `SELECT * FROM user WHERE name = ?;`;
      const result = await connection.execute(statement, [name]);
      return result[0];
    } catch (error) {
      console.log("user.service", error);
    }
  }
  async getUserByCellphone(cellphone) {
    try {
      const statement = `SELECT * FROM user WHERE cellphone = ?;`;
      const result = await connection.execute(statement, [cellphone]);
      return result[0];
    } catch (error) {
      console.log("user.service", error);
    }
  }
  async getUserByEmail(email) {
    try {
      const statement = `SELECT * FROM user WHERE email = ?;`;
      const result = await connection.execute(statement, [email]);
      return result[0];
    } catch (error) {
      console.log("user.service", error);
    }
  }
}

module.exports = new UserService();
